
export default async   function  viewPic(mediaPath) {
      try {
        // 先检查本地缓存
        const cachedPath = await checkImageCache(mediaPath);
        if (cachedPath) {
          return cachedPath;
        }
        
        // 没有缓存，下载并缓存图片
        return await downloadAndCacheImage(mediaPath);
      } catch (error) {
        console.error('获取图片失败:', error);
        return null
      }
    }
    

    async function checkImageCache(mediaPath) {
      const cacheMap = uni.getStorageSync('imageCacheMap') || {};
      const cacheKey = mediaPath; // 可以使用更复杂的键生成策略
      
      if (cacheMap[cacheKey]) {
        try {
          // 验证文件是否存在
          await verifyFileExists(cacheMap[cacheKey]);
          return cacheMap[cacheKey];
        } catch {
          // 文件不存在，移除无效缓存
        removeCacheEntry(cacheKey);
        }
      }
      return null;
    }
    
    /**
     * 验证文件是否存在
     */
   function verifyFileExists(filePath) {
      return new Promise((resolve, reject) => {
        uni.getFileInfo({
          filePath,
          success: resolve,
          fail: reject
        });
      });
    }
    
    /**
     * 下载并缓存图片
     */
    async function downloadAndCacheImage(url) {
      const downloadRes = await uni.downloadFile({ url });
      const saveRes = await uni.saveFile({
        tempFilePath: downloadRes.tempFilePath
      });
      
      // 更新缓存映射
   saveImageCacheMapping(url, saveRes.savedFilePath);
      return saveRes.savedFilePath;
    }
    
    /**
     * 保存图片缓存映射
     */
 function   saveImageCacheMapping(url, filePath) {
      const cacheMap = uni.getStorageSync('imageCacheMap') || {};
      cacheMap[url] = filePath;
      uni.setStorageSync('imageCacheMap', cacheMap);
    }
    
    /**
     * 移除缓存条目
     */
  function  removeCacheEntry(cacheKey) {
      const cacheMap = uni.getStorageSync('imageCacheMap') || {};
      if (cacheMap[cacheKey]) {
        delete cacheMap[cacheKey];
        uni.setStorageSync('imageCacheMap', cacheMap);
      }
    }
    
    /**
     * 图片加载成功处理
     */
 function   onImageLoad(url) {
      console.log('图片加载成功:', url);
    }

    /**
     * 图片加载失败处理
     */
   function onImageError(url) {
      console.log('图片加载失败:', url);
    }
  
